<!DOCTYPE html>

<html>
    
<?php

        $file_handle = fopen("conf.txt", "r");
        $line = split(":",fgets($file_handle));

        $hostname= $line[0];
        $db_user= $line[1];
        $db_pass= $line[2];
        $db_name= chop($line[3]);

        fclose($file_handle);

        session_start();

        $con = mysql_connect($hostname,$db_user,$db_pass);
        
        if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
        date_default_timezone_set('UTC');
        mysql_select_db($db_name, $con);
            
        if(!isset($_SESSION['username']))
        {
            header ('location:login.html'); // Make sure they are logged in!
        }
        else{
?>

<head>
        <title>Menú Sistemas</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"></meta>
        
        <link rel="Stylesheet" type="text/css" href="css/custom-theme/jquery-ui-1.9.1.custom.css" />
        <link rel="stylesheet" type="text/css" href="css/main.css">
        <link rel="Stylesheet" type="text/css" href="css/ui.jqgrid.css" />
        
        <script src="js/jquery-1.8.2.js"></script>
        <script src="js/jquery-ui-1.9.1.custom.min.js"></script>
        <script src="js/jquery-ui-1.9.1.custom.min.js"></script>
        <script src="js/grid.locale-es.js"></script>
        <script src="js/jquery.jqGrid.min.js"></script>
        <script src="js/rgbcolor.js"></script>
        <script src="js/canvg.js"></script> 
        <script src="js/highstock.js"></script>
        <script src="js/highcharts-more.js"></script>
        <script src="js/modules/exporting.js"></script>
        <script src="js/main.js"></script>
    </head>
    <body>
        <div id="wrapper">
            
            <div id="titulo">
                <?php 
                echo 'SISTEMA DE ANÁLISIS DE TENDENCIA VERSIÓN 1.0';
                ?> 
            </div>
            
            <div id="usuario">
                <?php 
                echo 'Bienvenido '.$_SESSION['username']." | <a href='logout.php'>Cerrar Sesión</a>"; 
                echo '<input type="text" id="user" value="'.$_SESSION['username'].'" style="display: none"/>';
                ?> 
            </div>

            <div id="menu">
                <ul>
                    <li><a id="inicio_a" href="#inicio">Inicio</a></li>
                    <li><a id="variables_a" href="#variables">Parámetros</a></li>
                    <li><a id="conf_grafico_a" href="#conf_grafico">Configuración Gráfico</a></li>
                    <li><a id="grafico_a" href="#grafico">Gráfico</a></li>
                    <li><a id="informes_a" href="#informes">Informes</a></li>
                </ul>
                <div id="inicio">
                     <div id="fecha_bd" style="margin-bottom: 1%;">
                    <fieldset>
                        <legend><h3>Última Actualización Base de Datos</h3></legend>
                        <h2><label id="date_bd"></label></h2>
                    </fieldset>
                     </div>
                    <div id="tutorial">
                    <fieldset>
                        <legend>Tutorial</legend>
                        <p style="text-align: center">El siguiente tutorial ilustra a modo de ejemplo, la manera de graficar el parámetro <b>VCO</b> perteneciente al sistema <b>RF</b>.</p>
                         <img src="images/tutorial.png" style="width: 80%;height: 80%;margin-left: 10%"/>
                    </fieldset>
                       
                     </div>
                </div>
                <div id="variables">
                   
                   <div id="sistemas">
                    <fieldset>
                        <legend><h4>Sistemas</h4></legend>
                        <table class="center">
                        <tr>
                    <td><input type="checkbox" id="aocs" class="sistema"/><label id="aocs_label" for="aocs" >AOCS</label></td>
            
                    <td><input type="checkbox" id="software" class="sistema" /><label id="software_label" for="software">SOFTWARE</label></td>
            
                    <td><input type="checkbox" id="power" class="sistema" /><label id="power_label" for="power">POWER</label></td>
            
                    <td><input type="checkbox" id="thermal" class="sistema" /><label id="thermal_label" for="thermal">THERMAL</label></td>
            
                    <td><input type="checkbox" id="payload" class="sistema" /><label id="payload_label" for="payload">PAYLOAD</label></td>
            
                    <td><input type="checkbox" id="rf" class="sistema" /><label id="rf_label" for="rf">RF</label></td>
                       </tr>
                       </table>
                   </fieldset>
                   </div>
                 
                 <div id="aocs_p" class="parametros">
                    <fieldset>
                        <legend><h4>AOCS Parámetros</h4></legend>
                        <table class="center">
                        <tr>
                       
<?php
        $i = 0;
        $sql = mysql_query('SELECT * FROM params;');
           
        while($row = mysql_fetch_array($sql))
             {
                if ($row['sistema'] == 'aocs'){
                   echo '<td><input type="checkbox" id="'.$row['nombre'].'" class="param'.$row['shortcut'].'" /><label id="'.$row['nombre'].'_label" for="'.$row['nombre'].'">'.str_replace('_',' ', strtoupper($row['nombre'])).'</label></td>';
                   $i++;
                }
                if ($i > 8){
                    echo '</tr><tr>';
                    $i = 0;
                }
             }

?>
                        </tr>
                        </table>
                    </fieldset>
                </div>
                    
                    <div id="aocs_s" class="shortcuts">
                        <fieldset>
                            <legend>AOCS Atajos</legend>
                            <table class="center">
                            <tr>
                                <?php
                                $before= '';
                                $sql = mysql_query('SELECT * FROM params;');
                                 
           
                                while($row = mysql_fetch_array($sql))
                                     {
                                        if ($row['sistema']=='aocs' && $row['shortcut'] != '' && $before !=$row['shortcut'] ){
                                            $shortcut_name = str_replace(' ','', $row['shortcut']);
                                            echo '<td><input type="checkbox" id="'.$shortcut_name.'" class="shortcut" /><label id="'.$shortcut_name.'_label" for="'.$shortcut_name.'">'.str_replace('_',' ', strtoupper($shortcut_name)).'</label></td>';
                                            $before = $row['shortcut'];
                                        }
                                        

                                     }

                                ?>
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                 
                    <div id="software_p" class="parametros">
                        <fieldset>
                            <legend>SOFTWARE Parámetros</legend>
                            <table class="center">
                            <tr>
                              
<?php  

        $sql = mysql_query('SELECT * FROM params;');
           
        while($row = mysql_fetch_array($sql))
             {
                if ($row['sistema'] == 'software'){
                   echo '<td><input type="checkbox" id="'.$row['nombre'].'" class="param'.$row['shortcut'].'" /><label id="'.$row['nombre'].'_label" for="'.$row['nombre'].'">'.str_replace('_',' ', strtoupper($row['nombre'])).'</label></td>';
                   
                }
                
             }

?>                 
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                    
                    <div id="software_s" class="shortcuts">
                        <fieldset>
                            <legend>SOFTWARE Atajos</legend>
                            <table class="center">
                            <tr>
                                <?php
                                $before= '';
                                $sql = mysql_query('SELECT * FROM params;');
                                 
           
                                while($row = mysql_fetch_array($sql))
                                     {
                                        if ($row['sistema']=='software' && $row['shortcut'] != '' && $before !=$row['shortcut'] ){
                                            $shortcut_name = str_replace(' ','', $row['shortcut']);
                                            echo '<td><input type="checkbox" id="'.$shortcut_name.'" class="shortcut" /><label id="'.$shortcut_name.'_label" for="'.$shortcut_name.'">'.str_replace('_',' ', strtoupper($shortcut_name)).'</label></td>';
                                            $before = $row['shortcut'];
                                        }
                                        

                                     }

                                ?>
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                    
                    
                    <div id="power_p" class="parametros">
                        <fieldset>
                            <legend>POWER Parámetros</legend>
                            <table class="center">
                            <tr>
                            <td><input type="checkbox" id="dod_manual" class="param DOD" /><label id="dod_manual_label" for="dod_manual">DOD MANUAL</label></td>
                              
<?php  
        $i = 0;
        $sql = mysql_query('SELECT * FROM params;');
           
        while($row = mysql_fetch_array($sql))
             {
                if ($row['sistema'] == 'power'){
                   echo '<td><input type="checkbox" id="'.$row['nombre'].'" class="param'.$row['shortcut'].'" /><label id="'.$row['nombre'].'_label" for="'.$row['nombre'].'">'.str_replace('_',' ', strtoupper($row['nombre'])).'</label></td>';
                   $i++;
                }
                if ($i > 9){
                    echo '</tr><tr>';
                    $i = 0;
                }
             }

?>                 
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                    
                    <div id="power_s" class="shortcuts">
                        <fieldset>
                            <legend>POWER Atajos</legend>
                            <table class="center">
                            <tr>
                                <?php
                                $before= '';
                                $sql = mysql_query('SELECT * FROM params;');
                                 
           
                                while($row = mysql_fetch_array($sql))
                                     {
                                        if ($row['sistema']=='power' && $row['shortcut'] != '' && $before !=$row['shortcut'] ){
                                            $shortcut_name = str_replace(' ','', $row['shortcut']);
                                            echo '<td><input type="checkbox" id="'.$shortcut_name.'" class="shortcut" /><label id="'.$shortcut_name.'_label" for="'.$shortcut_name.'">'.str_replace('_',' ', strtoupper($shortcut_name)).'</label></td>';
                                            $before = $row['shortcut'];
                                        }
                                        

                                     }

                                ?>
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                    
                    <div id="thermal_p" class="parametros">
                        <fieldset>
                            <legend>THERMAL Parámetros</legend>
                            <table class="center">
                            <tr>
                              
<?php  
        $i = 0;
        $sql = mysql_query('SELECT * FROM params;');
           
        while($row = mysql_fetch_array($sql))
             {
                if ($row['sistema'] == 'thermal'){
                   echo '<td><input type="checkbox" id="'.$row['nombre'].'" class="param'.$row['shortcut'].'" /><label id="'.$row['nombre'].'_label" for="'.$row['nombre'].'">'.str_replace('_',' ', strtoupper($row['nombre'])).'</label></td>';
                   $i++;
                }
                if ($i > 8){
                    echo '</tr><tr>';
                    $i = 0;
                }
             }

?>                 
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                    
                    <div id="thermal_s" class="shortcuts">
                        <fieldset>
                            <legend>THERMAL Atajos</legend>
                            <table class="center">
                            <tr>
                                <?php
                                $before= '';
                                $sql = mysql_query('SELECT * FROM params;');
                                 
           
                                while($row = mysql_fetch_array($sql))
                                     {
                                        if ($row['sistema']=='thermal' && $row['shortcut'] != '' && $before !=$row['shortcut'] ){
                                            $shortcut_name = str_replace(' ','', $row['shortcut']);
                                            echo '<td><input type="checkbox" id="'.$shortcut_name.'" class="shortcut" /><label id="'.$shortcut_name.'_label" for="'.$shortcut_name.'">'.str_replace('_',' ', strtoupper($shortcut_name)).'</label></td>';
                                            $before = $row['shortcut'];
                                        }
                                        

                                     }

                                ?>
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                    
                    <div id="payload_p" class="parametros">
                        <fieldset>
                            <legend>PAYLOAD Parámetros</legend>
                            <table class="center">
                            <tr>
                              
<?php  

        $sql = mysql_query('SELECT * FROM params;');
           
        while($row = mysql_fetch_array($sql))
             {
                if ($row['sistema'] == 'payload'){
                   echo '<td><input type="checkbox" id="'.$row['nombre'].'" class="param'.$row['shortcut'].'" /><label id="'.$row['nombre'].'_label" for="'.$row['nombre'].'">'.str_replace('_',' ', strtoupper($row['nombre'])).'</label></td>';
                }  
             }
?>                 
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                    
                    <div id="payload_s" class="shortcuts">
                        <fieldset>
                            <legend>PAYLOAD Atajos</legend>
                            <table class="center">
                            <tr>
                                <?php
                                $before= '';
                                $sql = mysql_query('SELECT * FROM params;');
                                 
           
                                while($row = mysql_fetch_array($sql))
                                     {
                                        if ($row['sistema']=='payload' && $row['shortcut'] != '' && $before !=$row['shortcut'] ){
                                            $shortcut_name = str_replace(' ','', $row['shortcut']);
                                            echo '<td><input type="checkbox" id="'.$shortcut_name.'" class="shortcut" /><label id="'.$shortcut_name.'_label" for="'.$shortcut_name.'">'.str_replace('_',' ', strtoupper($shortcut_name)).'</label></td>';
                                            $before = $row['shortcut'];
                                        }
                                        

                                     }

                                ?>
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                            
                    
                    <div id="rf_p" class="parametros">
                        <fieldset>
                            <legend>RF Parámetros</legend>
                            <table class="center">
                            <tr>
                              
<?php  
        $i = 0;
        $sql = mysql_query('SELECT * FROM params;');
           
        while($row = mysql_fetch_array($sql))
             {
                if ($row['sistema'] == 'rf'){
                    echo '<td><input type="checkbox" id="'.$row['nombre'].'" class="param'.$row['shortcut'].'" /><label id="'.$row['nombre'].'_label" for="'.$row['nombre'].'">'.str_replace('_',' ', strtoupper($row['nombre'])).'</label></td>';
                    $i++;
                }
                if ($i > 8){
                    echo '</tr><tr>';
                    $i = 0;
                }
                
             }

?>                 
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                                
                    <div id="rf_s" class="shortcuts">
                        <fieldset>
                            <legend>RF Atajos</legend>
                            <table class="center">
                            <tr>
                                <?php
                                $before= '';
                                $sql = mysql_query('SELECT * FROM params;');
                                 
           
                                while($row = mysql_fetch_array($sql))
                                     {
                                        if ($row['sistema']=='rf' && $row['shortcut'] != '' && $before !=$row['shortcut'] ){
                                            $shortcut_name = str_replace(' ','', $row['shortcut']);
                                            echo '<td><input type="checkbox" id="'.$shortcut_name.'" class="shortcut" /><label id="'.$shortcut_name.'_label" for="'.$shortcut_name.'">'.str_replace('_',' ', strtoupper($shortcut_name)).'</label></td>';
                                            $before = $row['shortcut'];
                                        }
                                        

                                     }

                                ?>
                            </tr>
                            </table>
                         </fieldset>
                    </div>            
                         
            </div>
                
                
                <div id="conf_grafico">
                    
                    <div id="advertencia_conf" class="ui-state-highlight ui-corner-all" style="padding: 0 .7em;">
                        <p>
                        <span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                        <strong>Atención:</strong>
                        No se ha elegido un parámetro o multiparámetro para graficar.
                        </p>
                    </div>
                    
                    <div id="dod_manual_param" class="param_frame">
                        <fieldset>
                            <legend>AOCS:DOD MANUAL</legend>
                            <b>Valor</b>:
                                <input type="radio" name="dod_manual_tipo" value="RPV" checked >RPV
                            <button value="dod_manual" class="eliminar" >Eliminar</button>
                        </fieldset>
                    </div>
                    
                    <?php
                    
                    $sql = mysql_query('SELECT * FROM params;');
           
                    while($row = mysql_fetch_array($sql))
                         {
                            echo '<div id="'.$row['nombre'].'_param" class="param_frame">'.
                                    ' <fieldset><legend><h3>'.strtoupper($row['sistema']).':'.strtoupper($row['nombre']).'</h3></legend><b>Valor</b>&nbsp';
                                    if ($row['OBV'] == 1){
                                        echo '<input class="tipo" type="radio" name="'.$row['nombre'].'_tipo" value="OBV">OBV';
                                    }
                                    
                                    echo '<input class="tipo" type="radio" name="'.$row['nombre'].'_tipo" value="RV">RV';
                                    
                                    if ($row['IPV'] == 1){
                                        echo '<input class="tipo" type="radio" name="'.$row['nombre'].'_tipo" value="IPV" checked>IPV';
                                    }
                                    if ($row['RPV'] == 1){
                                        echo '<input class="tipo" type="radio" name="'.$row['nombre'].'_tipo" value="RPV" checked>RPV';
                                    }
                                    if ($row['SPV'] == 1){
                                        echo '<input class="tipo" type="radio" name="'.$row['nombre'].'_tipo" value="SPV" checked>SPV';
                                        
                                    }
                                    
                              echo '&nbsp&nbsp<button value="'.$row['nombre'].'" class="eliminar">Eliminar</button>';
                              echo ' </fieldset></div>';
                         }
                    
                    ?>
                    <div id="fecha_modo">
                    <div id="fecha">
                        <fieldset>
                            <legend><h3>Fecha</h3></legend>
                            <label for="desde">Desde</label>
                                <input type="text" id="desde" name="desde"/>
                            <label for="hasta">Hasta</label>
                                <input type="text" id="hasta" name="hasta"/>
                        </fieldset>
                    </div>
                        
                        <div id="modo">
                            <fieldset>
                            <legend><h3>Modo</h3></legend>
                                <label for="normal_mode">Normal</label>
                                    <input type="radio" id="normal_mode" name="modo" value="normal" checked>
                                <label for="max_min_mode">Máx/Min</label>
                                    <input type="radio" id="max_min_mode" name="modo" value="max_min">
                            </fieldset>
                            
                        </div>
                    </div>
                    
                </div>     
                
                <div id="grafico">
                    <canvas id="canvas" width="700px" height="350px"  style="display:none"></canvas> 
                    <div id="advertencia_graf" class="ui-state-highlight ui-corner-all" style="padding: 0 .7em;">
                        <p>
                        <span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                        <strong>Atención:</strong>
                        No se ha elegido un parámetro o multiparámetro para graficar.
                        </p>
                    </div>
                
                <div id="dialog-form-informe" title="Informe">
                    
                    <p class="validateTips">Ingrese el nombre del informe</p>
                        
                    <form>
                    <fieldset>
                        <label for="nombre_informe">Nombre</label>
                        <input type="text" name="nombre_informe" id="nombre_informe" size="50" class="text ui-widget-content ui-corner-all" />
                    </fieldset>
                    </form>
                </div>

                </div>

                 <div id="informes">
                    
                        <div id="grid">
                            <table id="informe_grid"></table>
                            <div id="pagernav1"></div>
                            <br />
                            <table id="informe_final_grid"></table>
                            <div id="pagernav2"></div>
                            <br />
                            
                        </div>
                     
                     <div id="dialog-form-informe_final" title="Informe Final">
                    
                        <p class="validateTips">Ingrese el nombre del informe final</p>

                        <form>
                        <fieldset>
                            <label for="nombre_informe_final">Nombre</label>
                            <input type="text" name="nombre_informe_final" id="nombre_informe_final" size="62" class="text ui-widget-content ui-corner-all" /><br/><br/>
                            <label for="comment_informe_final">Comentario</label>
                            <textarea id="comment_informe_final" name="content" cols="50" rows="5"></textarea>
                        </fieldset>
                        </form>
                    </div>

                </div>
                
        </div>
</div>
<?php

}
mysql_close($con);
?> 
</body>
</html>